#!/usr/bin/perl
#act_lvcreate.cgi
require './lvm-lib.pl';
&ReadParse();
my ($vgname, $err_msg, $lvname, $vgfree, $size);

$vgname = $in{'vgname'};
$lvname = $in{'volname'};
$size = $in{'lvsize'};
$unit = $in{'unit'};
$vgfree = $in{'vgfree'};

if($size =~ /[^.0-9]/){
	$err_msg = $text{'invalid_size_format'};
	goto ERROR_OUT;
}
if($unit =~ /GB/){
	$size = $size * 1024;
}
elsif($unit =~ /MB/){
	$size = $size;	
}
my $lvsize = $size."M";
if($size > $vgfree){
	$err_msg = $text{'lv_size_exceed'};
	goto ERROR_OUT;
}

if(!$vgname || !($vgname =~ /\S/)){
	$err_msg = "No VG name! You must give it.";
	#goto ERROR_OUT;
}

@vginfo = get_vg_info();
foreach $vg (@vginfo) {
	if ($vg->{'vg'} eq $vgname) {
		$err_msg = $vgname."VG name used. Please change it.";
		#goto ERROR_OUT;
	}
}

my $rc = create_lv($lvname, $lvsize, $vgname);
if(!$rc){
	&redirect("index.cgi");
}else{
	$err_msg = $text{'err_createlv'};
	goto ERROR_OUT;
}
return;
ERROR_OUT:
&error_setup($text{'crt_err_title'});
&error($err_msg);
